use ash::vk;

use crate::{vulkan::{VkContext, vk_utils::utils_info}, VK_CHECK_UNSAFE, VK_LOGP};
use crate::VK_CHECK;

impl VkContext{
    pub fn get_descriptor_pool_ci() -> vk::DescriptorPoolCreateInfo {
        vk::DescriptorPoolCreateInfo {
            s_type      : vk::StructureType::DESCRIPTOR_POOL_CREATE_INFO,

            ..Default::default()
        }
    }

    pub fn create_descriptor_pool(&self) -> vk::DescriptorPool {
        let descriptor_pool_ci = Self::get_descriptor_pool_ci();
        // descriptor_pool_ci.command_buffer_count = command_buffer_count as u32;

        let command_buffers = match VK_CHECK!(unsafe {self.vk_device.create_descriptor_pool(&descriptor_pool_ci, None)}) {
            Some(inner_value)   => inner_value,
            None                => VK_LOGP!("Failed to create_descriptor_pool")
        };

        command_buffers
    }

    /// 创建多个Framebuffer
    /// 多个Color_attachment共享depth_attachment
    pub fn create_framebuffer(&self, width: u32, height: u32, render_pass: &vk::RenderPass, attachments: &Vec<vk::ImageView>) -> vk::Framebuffer {
        let mut framebuffer_ci = utils_info::get_framebuffer_ci();
        framebuffer_ci.width            = width;
        framebuffer_ci.height           = height;
        framebuffer_ci.render_pass      = *render_pass;
        framebuffer_ci.layers           = 1;

        framebuffer_ci.p_attachments    = attachments.as_ptr();
        framebuffer_ci.attachment_count = attachments.len() as u32;
        
        match VK_CHECK_UNSAFE!(self.vk_device.create_framebuffer(&framebuffer_ci, None)) {
            Some(inner_value)   => inner_value,
            None                => VK_LOGP!("Failed to create_framebuffer")
        }
    }

}